// pages/findMusic/findMusic.js
const {getFindMusicHttp,getNewestHttp,getDjProgramHttp}= require("../../models/findMusic")
Page({
  data: {
    value:{}
  },
  onLoad: async function (options) {
    let value = this.data.value;
    let hot = await getFindMusicHttp()
    let newest = await getNewestHttp()
    let dj = await getDjProgramHttp()

    let http = [getFindMusicHttp,getNewestHttp,getDjProgramHttp];
    for (let item of http){
      let res = await item();
      // console.log(res);
    }

    // 处理最热歌单的数据
    let hotMusic = [];
    hot.data.playlists.forEach(element => {
      let {name,id,coverImgUrl,playCount} = element
      hotMusic.push({
        name,
        coverImgUrl,
        id,
        playCount
      })
    });
    // 处理最新歌单的数据
    let newMusic = [];
    newest.data.albums.forEach(element => {
      let {name,id,picUrl,} = element
      newMusic.push({
        name,
        coverImgUrl:picUrl,
        id
      })
    });
    // 处理dj歌单的数据
    let djMusic = [];
    dj.data.result.forEach(element => {
      let {name,id,picUrl,} = element
      djMusic.push({
        name,
        coverImgUrl:picUrl,
        id
      })
    });

    Object.assign(value,
      {
        hotMusic:{
        title:"热门歌曲",
        music:hotMusic.slice(0,6),
        imgURL:"/images/hotMusic.png"
        }
      },
      {
        newMusic:{
          title:"最新音乐",
          music:newMusic.slice(0,3),
          imgURL:"/images/newMusic.png"
        },
      },
      {
        djMusic:{
          title:"主播电台",
          music:djMusic.slice(0,6),
          imgURL:"/images/djMusic.png"
        },
      }
    )
    this.setData({
      value
    })
    // console.log(value);
  },
})